/*
package pattern.controller;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.img.ImgUtil;
import com.arcsoft.face.FaceInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pattern.WorkServiceTool;
import pattern.annontations.Secure;
import pattern.cache.InitCache;
import pattern.currentsession.ContextLocalCache;
import pattern.dto.UserFaceInfo;
import pattern.itboyst.facedemo.FaceTool;
import pattern.itboyst.facedemo.model.FaceSearchResDto;
import pattern.itboyst.facedemo.model.UserFaceInfoPojo;
import pattern.result.ResponseData;
import pattern.result.ResponseResultStatus;
import pattern.utils.CollectionUtil;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

*/
/**
 * @author Simon
 * @date 2021-03-31
 *//*

@Api(tags = "人脸识别")
@RestController
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Secure
@Slf4j
public class UserFaceInfoController {

    private final InitCache initCache;

    @PostMapping(value = "/api/face_add")
    @ApiOperation(value = "人脸添加")
    public ResponseData<Boolean> faceAdd(@RequestParam("file") String file) {
        if (StringUtils.isBlank(file)) {
            return new ResponseData<>(Boolean.FALSE);
        }
        var userFaceInfos = WorkServiceTool.getUserFaceInfoService().getBaseMapper().selectList(new QueryWrapper<UserFaceInfo>().eq(UserFaceInfo.PROD_GROUPID, ContextLocalCache.get().getWorkerId()));
        if (CollectionUtil.isNotEmpty(userFaceInfos)) {
            return new ResponseData<>(ResponseResultStatus.FAILED, "当前账号人脸已录入存在");
        }
        var userFaceInfo = FaceTool.faceAdd(file, ContextLocalCache.get().getWorkerId(), ContextLocalCache.get().getUserName());
        var save = WorkServiceTool.getUserFaceInfoService().getBaseMapper().insert(userFaceInfo);
        return new ResponseData<>(save > 0);
    }

    @PostMapping(value = "/api/face_search")
    @ResponseBody
    @ApiOperation(value = "人脸识别")
    public ResponseData<FaceSearchResDto> faceSearch(@RequestParam("file") String file) throws Exception {
        List<UserFaceInfo> faceInfoList = WorkServiceTool.getUserFaceInfoService().getBaseMapper().selectList(new QueryWrapper<UserFaceInfo>().eq(UserFaceInfo.PROD_GROUPID, ContextLocalCache.get().getWorkerId()));
        var userFaceInfoPojo = CollectionUtil.toTargetList(faceInfoList, UserFaceInfoPojo.class);
        var faceSearchResDto = FaceTool.faceSearch(file, userFaceInfoPojo);
        return new ResponseData<>(faceSearchResDto);
    }

    @PostMapping(value = "/api/face_detect")
    @ResponseBody
    @ApiOperation(value = "人脸检查")
    public ResponseData<List<FaceInfo>> detectFaces(String image) throws IOException {
        return new ResponseData<>(FaceTool.detectFaces(image));
    }

    @GetMapping(value = "/api/get_mine_face")
    @ResponseBody
    @ApiOperation(value = "获取登录用户人脸")
    public ResponseData<String> getMineFace() {
        var userFaceInfos = WorkServiceTool.getUserFaceInfoService().getBaseMapper().selectOne(new QueryWrapper<UserFaceInfo>().eq(UserFaceInfo.PROD_GROUPID, ContextLocalCache.get().getWorkerId()));
        if (Objects.isNull(userFaceInfos)) {
            return new ResponseData<>();
        }
        var encode = Base64.encode(userFaceInfos.getMineFace());
        if (StringUtils.isNotBlank(encode)) {
            var responseData = new ResponseData<String>(ResponseResultStatus.SUCCESS);
            var img = ImgUtil.scale(ImgUtil.toImage(encode), 0.25F);
            responseData.setData(ImgUtil.toBase64DataUri(img,"png"));
            return responseData;
        }
        return new ResponseData<>();
    }

    @DeleteMapping(value = "/api/delete_mine_face")
    @ResponseBody
    @ApiOperation(value = "删除用户人脸")
    public ResponseData<Boolean> deleteMineFace() {
        var success = WorkServiceTool.getUserFaceInfoService().getBaseMapper().delete(new QueryWrapper<UserFaceInfo>().eq(UserFaceInfo.PROD_GROUPID, ContextLocalCache.get().getWorkerId()));
        return new ResponseData<>(success>0);
    }


}
*/
